<template>
	<view class="container">
		<view class="wal_det">
			<view class="det_item" v-for="(item, index) in list" :key="index">
				<view class="det_main">
					<view class="det_tit">{{ item.reason }}</view>
					<view class="det_time">{{ item.create_time }}</view>
				</view>
				<view class="det_money">
					<p v-if="item.type == 1" >+{{ item.money }}</p>
					<p v-if="item.type == 2" >-{{ item.money }}</p>
				</view>
			</view>
			<view class="uni-loadmore text-white" v-if="showLoadMore">{{loadMoreText}}</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				income: 0.00,
				expend: 0.00,
				page: 1,
				lastPage: 0,
				list: [],
				loadMoreText: "加载中...",
				showLoadMore: false
			};
		},
		onUnload() {
			this.page = 1
			this.lastPage = 0
			this.list = []
			this.loadMoreText = "加载更多"
			this.showLoadMore = false;
		},
		onLoad: function (option) {
			this.helper.checkLogin();
			this.getData();
			setTimeout(() => {
				this.getData();
			}, 10);
		},
		onReachBottom() {
			console.log("onReachBottom");
			if (this.page > this.lastPage) {
				this.loadMoreText = "没有更多数据了!"
				return;
			}else{
				this.showLoadMore = true;
				setTimeout(() => {
					this.getData();
				}, 300);
				setTimeout(() => {
					this.getData();
				}, 10);
			}
		},
		onPullDownRefresh() {
			this.page = 1
			this.lastPage = 0
			this.list = []
			this.loadMoreText = "加载更多"
			this.showLoadMore = false;
			
			setTimeout(() => {
				this.getData();
			}, 300);
		},
		methods: {
			getData:function(){
				//获取基础参数
				// uni.showLoading({
				// 	title:"数据加载中",
				// 	mask:true
				// })
				let page = this.page;
				let info = uni.getStorageSync("userinfo");
				let timestamp = this.helper.now();
				let sign = this.helper.setSign(['token='+info.token,'page='+page,'timestamp='+timestamp, 'size=20']);
				this.helper.req({
					api:"getBill",
					timestamp:timestamp,
					data:{token:info.token,page:page,size:20},
					header:{sign:sign},
					method:'GET',
				}).then(res=>{
					let current_page = res.data.data.list.current_page;
					let last_page = res.data.data.list.last_page;
					this.page = current_page + 1;
					this.lastPage = last_page;
					this.list = this.list.concat(res.data.data.list.data);
					if (this.page >= this.lastPage) {
						this.loadMoreText = "没有更多数据了!"
					}
					this.income = res.data.data.income;
					this.expend = res.data.data.expend;
					
					uni.stopPullDownRefresh();
					uni.hideLoading();
				})
			},
			//链接
			toUrl:function(url){
				// console.log(url);
				uni.navigateTo({
					url: url,
				});	
			},
		},
	};
</script>

<style lang="scss">
page {
		background-color: #ddeafd;
	}
	
	.info_bg{
		position: absolute;
		width: 100%;
		height: 100%;
		left: 0;
		top: 0;
		background-color: #fff;
	 
		border-radius:10px;
	}
	
	.wal_det{
		position: relative;
		 margin: 0 30rpx;
		 box-shadow: 0px 4px 9px 3px #b6ccf2;
		// height: 30vw;
		margin: 4vw;
		padding: 0;
		background: #fff;
		border-radius: 10rpx;
		
		.det_item{
			color: #4f8efd;
			font-size: 16px;
			display: flex;
			margin: 0 4vw;
			border-bottom: 0.5px solid #EEE;
			display: flex;
			align-items: center;
			.det_img{
				width: 16vw;
				image{
					width: 10vw;
					 
					margin: 4vw 2vw;
				}
			}
			.det_main{
				width: 64vw;
				padding-top: 2vw;
				
				.det_tit{
					width: 64vw;
					font-size: 13px;
					overflow: hidden;
				}
				.det_number{
					width: 48vw;
					line-height: 7vw;
					font-size: 12px;
					color:#DDD;
				}
				.det_time{
					width: 60vw;
					line-height: 7vw;
					font-size: 12px;
					color:#DDD;
				}
			}
			.det_money{
				width: 22vw;
				 
				font-size: 12px;
				color:#353535;
				text-align: right;
				p{
					line-height: 40px;
				}
				.text-xs{
					line-height: 30px;
					font-size: 16px;
				}
			}
			.cuIcon-right{
				line-height: 16vw;
			}
		}
		.det_item:last-child{
			border: none;
		}
	}
</style>